package com.nbjtjc.safe.api.emg.handle;

import cn.hutool.core.util.ObjectUtil;
import com.nbjtjc.safe.annotation.SysLog;
import com.nbjtjc.safe.bean.Result;
import com.nbjtjc.safe.mapper.emg.handle.EmgHandlePublicGoodsMapper;
import com.nbjtjc.safe.model.emg.handle.EmgHandleGoods;
import com.nbjtjc.safe.model.emg.handle.EmgHandlePublicGoods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/emgHandlePublicGoods")
@CrossOrigin("*")
public class EmgHandlePublicGoodsController {

    @Autowired
    private EmgHandlePublicGoodsMapper emgHandlePublicGoodsMapper;


    @SysLog("添加发布的应急处置的物资")
    @RequestMapping(value = "/add",method = {RequestMethod.POST})
    public Result add(@RequestBody EmgHandlePublicGoods emgHandlePublicGoods){
        Result result=new Result();
        if(ObjectUtil.isNull(emgHandlePublicGoods)
                ||ObjectUtil.isNull(emgHandlePublicGoods.getHandlePublicId())){
            result.setFalse("不能为空");
            return result;
        }
        try {
            emgHandlePublicGoodsMapper.insert(emgHandlePublicGoods);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    @SysLog("删除发布的应急处置中的关联物资")
    @RequestMapping(value = "/delete",method = {RequestMethod.POST})
    public Result delete(@RequestBody EmgHandlePublicGoods emgHandlePublicGoods){
        Result result=new Result();
        if(ObjectUtil.isNull(emgHandlePublicGoods)||ObjectUtil.isNull(emgHandlePublicGoods.getId())){
            result.setFalse("不能为空");
            return result;
        }
        try {
            emgHandlePublicGoodsMapper.deleteByPrimaryKey(emgHandlePublicGoods);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }
}
